package com.example.ccsystem.controller;

import com.example.ccsystem.entity.Student;
import com.example.ccsystem.entity.Teacher;
import com.example.ccsystem.service.TeacherService;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Teacher")
public class TeacherController {
    @Autowired
    private TeacherService service;

    @ApiOperation(value="获取教师总数",notes = "")
    @RequestMapping(value = "/getAllTeachers",method = RequestMethod.GET)
    public String getAllTeachers(){
        return service.getAllTeachers();
    }

    @ApiOperation(value="获取教师列表",notes="")
    @RequestMapping(value = "/",method = RequestMethod.GET)
    public List<Map<String,Object>> findAllTeachers(){
        List<Map<String,Object>> list=service.findAllTeacher();
        return list;
    }

    @ApiOperation(value="获取教师",notes = "根据教师id获取教师信息")
    @RequestMapping(value = "/{tid}",method = RequestMethod.GET)
    public Teacher getBySId(@PathVariable int tid){
        Teacher teacher=service.getByTId(tid);
        return teacher;
    }

    @ApiOperation(value="添加教师",notes="添加教师")
    @RequestMapping(value = "/",method = RequestMethod.POST)
    public int addTea(Teacher teacher){
        int res=service.addTea(teacher);
        return res;
    }

    @ApiOperation(value="删除教师",notes = "根据教师号删除教师")
    @RequestMapping(value="/{tid}",method = RequestMethod.DELETE)
    public int deleteTea(@PathVariable int tid){
        System.out.println(tid);
        int res=service.deleteTea(tid);
        return res;
    }

    @ApiOperation(value="修改教师信息",notes = "根据教师号修改教师信息")
    @RequestMapping(value = "/",method = RequestMethod.PUT)
    public int updateTea(Teacher teacher){
        System.out.println(teacher.getTid());
        int isHas=service.isHasTea(teacher.getTid());
        int res=0;
        if(isHas==1){
            res=service.updateTea(teacher);
        }
        return res;
    }
}
